#include "view_time_1.h"
#include "view_time_1.inc"
#include "view_time_0.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "view_common.h"
#include "app_trace.h"
#include "weather_ctrl.h"
#include "view_times.h"
#include "math.h"
#ifdef TIME_1_SKIP
#else

void view_time_1_ble(bool connect, int x, int y)
{
	  if (connect)
    {
        disp_draw_user_image_filter_color(x, y, img_time_1_connect);
    }
    else
    {
        disp_draw_user_image_filter_color(x, y, img_time_1_disconnect);
    }
}

static void view_time_1_time(void)
{
	const uint8_t img_time_1_time_hour_num_TAB[]=
	{
		FILE_IMG_data2_font_hour_16_15_0,
		FILE_IMG_data2_font_hour_16_15_1,
		FILE_IMG_data2_font_hour_16_15_2,
		FILE_IMG_data2_font_hour_16_15_3,
		FILE_IMG_data2_font_hour_16_15_4,
		FILE_IMG_data2_font_hour_16_15_5,
		FILE_IMG_data2_font_hour_16_15_6,
		FILE_IMG_data2_font_hour_16_15_7,
		FILE_IMG_data2_font_hour_16_15_8,
		FILE_IMG_data2_font_hour_16_15_9,
	};
	
	const uint8_t img_time_1_time_minute_num_TAB[]=
	{
		 FILE_IMG_data2_font_min_16_63_0,
		 FILE_IMG_data2_font_min_16_63_1,
		 FILE_IMG_data2_font_min_16_63_2,
		 FILE_IMG_data2_font_min_16_63_3,
		 FILE_IMG_data2_font_min_16_63_5,
		 FILE_IMG_data2_font_min_16_63_6,
		 FILE_IMG_data2_font_min_16_63_7,
		 FILE_IMG_data2_font_min_16_63_8,
		 FILE_IMG_data2_font_min_16_63_9,
	};
	
	int x = 16;
	int y = 16;
	int front_width = 48;
	int front_height = 46;
	int front_width_spacing = 3;
	int front_height_spacing = 2;
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_0,x,y,img_time_1_time_hour_num_TAB[disp_ctrl.com_data.i_temp[3]/10]);
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_1,x+front_width+front_width_spacing,y,img_time_1_time_hour_num_TAB[disp_ctrl.com_data.i_temp[3]%10]);
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_2,x,y+front_height_spacing+front_height,img_time_1_time_minute_num_TAB[disp_ctrl.com_data.i_temp[4]/10]);
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_3,x+front_width+front_width_spacing,y+front_height_spacing+front_height,img_time_1_time_minute_num_TAB[disp_ctrl.com_data.i_temp[4]%10]);
}

void view_time_1_battery(void)
{
	if(disp_ctrl.com_data.i_temp[7]<=0)
	{
		disp_draw_user_image(102,5,img_time_1_battery_level_last);
		return;
	}
	int battery = (disp_ctrl.com_data.i_temp[7]/10)-1;
	disp_draw_user_image(102,5,img_time_1_battery_level_TAB[battery]);
}

static void view_time_1_step(void)
{
	int steps = disp_ctrl.com_data.i_temp[11];
	int x = 8;
	int y = 111;
	int steps_schedule = steps/8000;
	const uint8_t img_time_1_steps_schedule[]=
	{
		FILE_IMG_data2_icon_steps_8_110_1,
		FILE_IMG_data2_icon_steps_8_110_2,
		FILE_IMG_data2_icon_steps_8_110_3,
		FILE_IMG_data2_icon_steps_8_110_4,
		FILE_IMG_data2_icon_steps_8_110_5,
		FILE_IMG_data2_icon_steps_8_110_6,
		FILE_IMG_data2_icon_steps_8_110_7,
		FILE_IMG_data2_icon_steps_8_110_8,
		FILE_IMG_data2_icon_steps_8_110_9,
		FILE_IMG_data2_icon_steps_8_110_10,
	};
	if(steps<=1000)
	{
		_disp_show_flash_img(DISP_LFS_FILE_INDEX_4,x,y,FILE_IMG_data2_icon_steps_8_110_0);
	}
	else
	{
		_disp_show_flash_img(DISP_LFS_FILE_INDEX_4,x,y,img_time_1_steps_schedule[steps_schedule]);
	}
	disp_draw_user_image(43,174,img_time_1_steps_icon);
	disp_draw_user_image_num_mid_gray_lucency(59,141,RGB565_COLOR_WHITE,steps,11, img_time_1_step_num_TAB);
}

void view_time_1_display(void)
{
	view_time_1_time();
	view_time_1_ble(disp_ctrl.com_data.i_temp[7],7,5);
  view_time_1_battery();
	view_time_1_step();
}
#endif
